package cn.com.project.pattern.q.chain;

/**
 * @Desc 责任链模式，处理者
 * @Author wangjun
 * @Date 2018-02-27
 */
public abstract class Handler {
	// 处理级别
	private int level = 0;
	// 下一个责任人
	private Handler nextHandler;
	// 每个类能处理的级别
	public Handler(int level) {
		this.level = level;
	}
	// 设置下一个责任人
	public void setNext(Handler handler) {
		this.nextHandler = handler;
	}
	// 回应请求
	public abstract void response(IStaff staff);
	
	// 处理请求
	public final void handlerMessage(IStaff staff) {
		if (staff.getType() == this.level) {
			this.response(staff);
		} else {
			if (this.nextHandler != null) {
				this.nextHandler.handlerMessage(staff);
			} else {
				System.out.println("----------没办法处理！");
			}
		}
	}
	
}
